<style>
    .btn-red{
        background-color: #F92659;
    }
    </style>
<section id="main-content">
    <section class="wrapper">
    <!-- page start-->
        <div class="row">
            <div class="col-lg-12">
                <section class="panel panel-info">
                    <header class="panel-heading">
                        区域级别查询
                    </header>
                    <div class="panel-body">
                        <form class="navbar-form " role="search" method="post" target="_self">
                            <div class="form-group">
                                <select class="btn btn-default" name="province" id="province">
                                    <option value="">--请选择--</option>
                                    <?php if(!empty($province)){foreach($province as $k => $v){?>
                                        <option value="<?php echo $v['id']?>" <?php if(!empty($data['province'] ) && $data['province'] == $v['id']){echo "selected";}?>><?= $v['name'];?></option>
                                    <?php }}?>
                                </select>
                                <select name="city" id="city"  class="btn btn-default">
                                    <?php if(!empty($city)){foreach($city as $k => $v){?>
                                        <option value="<?php echo $v['id']?>" <?php if(!empty($data['city'] ) && $data['city'] == $v['id']){echo "selected";}?>><?= $v['name'];?></option>
                                    <?php }}else{?>
                                    <option value="">请选择</option>
                                    <?php }?>
                                </select>
                            </div>
                            <button type="button" class="btn btn-info slecctform">查询</button>
                        </form>
                    </div>
                    <ul class="list-group list-area">
                        <?php if(!empty($model)){foreach ($model as $k=>$v){?>
                            <li class= 'list-group-item'>
                                <span style="float:left;display: inline-block"><?php echo !empty($v['areaName']) ? $v['areaName'] : '-';?></span>
                                <span style="float:right;display: inline-block"><?php echo !empty($v['message']) ? $v['message'] : '-';?></span>
                                <?php if(Yii::$app->cache->get('admin')['role'] == 1){?>
                                <span style="float: right;display: inline-block">
                                    <input type="hidden" class="id" value="<?php echo $v['id']?>">
                                    <button type="button" class="btn btn-xs btn-primary set_level" data-toggle="modal" data-target="#myModal1">设置</button>
                                </span>
                                <?php }?>
                            </li>
                        <?php }}?>
                    </ul>
                </section>
            </div>
        </div>
    <!-- page end-->
    </section>
</section>
<div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title">城市级别设置</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="ibox float-e-margins">
                                <div class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label"><span class="text-danger">*</span>城市级别名称：</label>
                                        <div class="col-sm-5">
                                            <select class="form-control level" name="level" id="level">
                                                <?php if(!empty($level)){foreach($level as $k => $v){?>
                                                    <option value="<?php echo $k?>"><?= $v;?></option>
                                                <?php }}?>
                                            </select>
                                            <input type="hidden" id="id">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary setLevel" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
</div>
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
//省和市二级联动
$('#province').on('change', function () {
    var obj = $(this);
    if (!obj.val()) {
        $("#city").empty();
        $("#city").append("<option value=''>请选择/option>");
        return false;
    }
    if (!$(this).hasClass('children')) {
        $.ajax({
            url: '/sign/get-list',
            type: 'post',
            dataType: 'json',
            data: "province="+obj.val(),
            success: function (res) {
                $("#city").empty();
                var html = "<option value=''>请选择</option>";
                for (a in res.data) {
                    html += '<option value="' + res.data[a].id + '" >' + res.data[a].name + '</option>';
                }
                $("#city").append(html);
            }
        });
    }
});

$(".slecctform").click(function(){
    var str = "1=1";
    var province = $("#province").val();
    if(province.length == 0){
        alert('请选择搜索省份');
        return false;
    }else{
        str += "&province="+province;
    }
    var city = $("#city").val();
    if(city.length == 0){
        alert('请选择搜索城市');
        return false;
    }else{
        str += "&city="+city;
    }
    window.location.href='citys?'+str;
});
$(".set_level").click(function(){
    var id = $(this).siblings(".id").val();
    $("#id").val(id);
});

$(".setLevel").click(function(){
    var id = $("#id").val();
    var level = $("#level").val();
    $.ajax({
        type: "post",
            url: "city-level-ajax-do",
            data: {id:id,level:level},
            dataType: "json",
            success: function(param){
            if(param.code == '20000'){
                location.reload();
            }else{
                alert(param.message);
            }
          }
    });
});
</script>
